package com.hx.portal.controller.user;


import com.hx.common.exception.CustomerException;
import com.hx.common.result.Result;

import com.hx.hospital.service.SmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Authorization;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/sms")
@RestController
@ResponseBody
@Api(description = "短信相关接口文档")
public class SmsController {

    @Reference
    private SmsService smsService;


    @PostMapping(value = "/login")
    @ApiOperation(value = "发送一键登录短信",notes = "发送一键登录短信",httpMethod = "POST",authorizations = {@Authorization(value = "token")})
    public Result sendLoginSms(  String phone) throws CustomerException {
        if(!phone.matches("^[1](([3][0-9])|([4][5,7,9])|([5][0-9])|([6][6])|([7][3,5,6,7,8])|([8][0-9])|([9][8,9]))[0-9]{8}$")){
            return new Result(5003,"手机号码格式不合法");
        }

        smsService.sendLoginSms(phone);
        return new Result();
    }


}
